package com.sto.stoapp.broadcast;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.sto.stoapp.activity.StoVehicleManagerActivity;
import com.sto.stoapp.activity.administrator.StoAdminMainActivity;
import com.sto.stoapp.activity.aviation.StoAviationPickUpMainActivity;
import com.sto.stoapp.activity.aviation.StoAviationScannerMainActivity;
import com.sto.stoapp.activity.aviation.StoAviationSelectActivity;
import com.sto.stoapp.activity.center.StoCenterMainActivity;
import com.sto.stoapp.activity.sales.StoSalesMainActivity;
import com.sto.stoapp.activity.scanner.StoScanMainActivity;
import com.sto.stoapp.log.ExceptionLog;
import com.sto.stoapp.manager.AlarmClockManager;
import com.sto.stoapp.util.Helper;
import com.sto.stoapp.util.UnifiedStaticType;

/**
 * 登出到登陆界面的广播
 * 
 * @author mgf
 * 
 */
public class LogoutBroad extends BroadcastReceiver implements HomeBroadAction {

	@Override
	public void onReceive(Context context, Intent intent) {
		String action = intent.getAction();
		System.out.println("action = " + action);
		String logout = intent
				.getStringExtra(AlarmClockManager.ALARM_CLOCK_TYPE);
		ExceptionLog.writeLog("LogoutBroad",Helper.getVersionName(context)+ "/n action:"+action+"/n");
		// 业务员模块
		if (action.equals(SALES_MAN_BROAD)) {
			intent.setClass(context, StoSalesMainActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			if (logout != null && !logout.equals("")) {
				Helper.loginOut(context);
				intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
			}
			UnifiedStaticType.NOT_CLOSE=true;
			context.startActivity(intent);
			((Activity) context).finish();
		}
		// 管理员模块
		else if (action.equals(ADMINISTRATOR_BROAD)) {
			
			ExceptionLog.writeLog("LogoutBroad onReceive admin", action);
			
			intent.setClass(context, StoAdminMainActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			if (logout != null && !logout.equals("")) {
				Helper.loginOut(context);
				intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
			}
			context.startActivity(intent);
			((Activity) context).finish();
		}
		// 扫描员模块
		else if (action.equals(SCANNER_MAN_BROAD)) {
			intent.setClass(context, StoScanMainActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			if (logout != null && !logout.equals("")) {
				Helper.loginOut(context);
				intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
			}
			UnifiedStaticType.NOT_CLOSE=true;
			context.startActivity(intent);
			((Activity) context).finish();
		}
		// 中转模块
		else if (action.equals(CENTER_BROAD)) {
			ExceptionLog.writeLog("LogoutBroad onReceive center", action);
			intent.setClass(context, StoCenterMainActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			if (logout != null && !logout.equals("")) {
				Helper.loginOut(context);
				intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
			}
			UnifiedStaticType.NOT_CLOSE=true;
			context.startActivity(intent);
			((Activity) context).finish();
		}
		// 车辆管理模块
		else if (action.equals(VEHICLE_MANAGER_BROAD)) {
			intent.setClass(context, StoVehicleManagerActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			if (logout != null && !logout.equals("")) {
				Helper.loginOut(context);
				intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
			}
			context.startActivity(intent);
			((Activity) context).finish();
		}
		// 航空模块（航空选择界面）
		else if (action.equals(AVIATION_BROAD)) {
		    intent.setClass(context, StoAviationSelectActivity.class);
		    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (logout != null && !logout.equals("")) {
                Helper.loginOut(context);
                intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
            }
            context.startActivity(intent);
            ((Activity) context).finish();
		}
		// 航空提货员
		else if (action.equals(PICKER_BROAD)) {
            intent.setClass(context, StoAviationPickUpMainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (logout != null && !logout.equals("")) {
                Helper.loginOut(context);
                intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
            }
            context.startActivity(intent);
            ((Activity) context).finish();
        }
		// 航空扫描员
		else if (action.equals(AVIATION_SCANNER_BROAD)) {
		    intent.setClass(context, StoAviationScannerMainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (logout != null && !logout.equals("")) {
                Helper.loginOut(context);
                intent.putExtra(AlarmClockManager.ALARM_CLOCK_TYPE, logout);
            }
            context.startActivity(intent);
            ((Activity) context).finish();
        }
        else{
        	
        }
	}

}
